package my.jwds.p83;

import my.jwds.p21.ListNode;

public class DeleteDuplicates {

    public static void main(String[] args) {
        DeleteDuplicates o = new DeleteDuplicates();
        ListNode head = ListNode.to(new int[]{1,1,2,3,3});
        System.out.println(o.deleteDuplicates(head));
    }


    public ListNode deleteDuplicates(ListNode head) {
        ListNode temp = new ListNode(-101);
        ListNode result = temp;
        while(head != null){
            if (temp.val != head.val){
                temp.next = head;
                temp = temp.next;
                head = head.next;
                temp.next = null;
            }else{
                head = head.next;
            }
        }

        return result.next;
    }
}
